//修改个人信息
var nationality,prAddrProvince,prAddrCity,curAddrProvince,curAddrCity,curAddrCounty,curAddrStreet;
//************************************批量申请**************************************************
function getApplicationBatchInfo(data){
	if(data.statusCode==DWZ.statusCode.error){
		navTabAjaxDone(data)
	}else{
		var currentPage;
		 var numPerPage;
		 var pageCount; 
		 var totalCount
		 var index;
		 var content="";
		 $(data).each(function(n,item){
			 var files=item.pagedList;
			 if(files.length==0){
					content+="<tr><td colspan='2' align='center' >未查询到文件</td></tr>"
			}else{
				 for(index=0;index<files.length;index++){
					 content+="<tr onmouseover='moveoverMouse(this)' onmouseout='moveoutMouse(this)' align='center'><td ><input  name='ids'  type='radio' value="+files[index].applyBatchNo+" /></td><td  >"+files[index].applyBatchNo+"</td><td  id="+files[index].applyBatchNo+"></td></tr>"; 
				 }
			}
			 $("#totalCountByBatchApplication").text("条，共"+item.totalCount+"条");
			 $("select[name='numPerPage']").val(item.numPerPage); 
			 currentPage=item.currentPage;
			 numPerPage=item.numPerPage;
			 pageCount=item.pageCount;
			 totalCount=item.totalCount;
			 $("input[name='pageNum']").val(currentPage);
			 $("input[name='numPerPage']").val(numPerPage);
//			 $("input[name='pageCount']").val(pageCount);
			 $("#tbodyByBatchApplication").html(content);
//			 var pagination="<a href='#' onclick="+"previous($('#getApplicationBatchInfo'),getApplicationBatchInfo) id='previous' >上一页  </a><a href='#' onclick="+"next($('#getApplicationBatchInfo'),getApplicationBatchInfo) id='next'> 下一页</a><span>当前第"+item.currentPage+"页，共"+item.pageCount+"页</span>";
//			 $("#paginationByBatchApplication").html(pagination);
			 $("#paginationByBatchApplication").addClass("pagination").attr("targetType","navTab").attr("totalCount",totalCount).attr("numPerPage",numPerPage).attr("pageNumShown","10").attr("currentPage",currentPage).attr("rel","tbodyByBatchApplication").attr("callback","getApplicationBatchInfo");
			 $("div.pagination").each(function(){
				var $this = $(this);
				$this.pagination({
					targetType:"navTab",
					rel:"tbodyByBatchApplication",
					totalCount:totalCount,
					numPerPage:numPerPage,
					pageNumShown:10,
					currentPage:currentPage,
					callback:getApplicationBatchInfo
				});
			});
		 });
		 var $p = $("#ByAppBatch");
			initUI($p);
	}
		 
};

//导入任务刷新-------------------------------------------------------------- 
 function getApplicationBatchRefresh(errorFiles){
	 if(errorFiles.statusCode==DWZ.statusCode.error){
			navTabAjaxDone(errorFiles)
	}else{
		var length = errorFiles.length
		 var currentPage;
		 var numPerPage;
		 var pageCount; 
		 var index;
		 var content="";
		 $.post("applicationBatch/getFilesByEmport",function(data){
			 $(data).each(function(n,item){
				 var files=item.pagedList;
				 if(files.length==0){
						content+="<tr><td colspan='2' align='center' >未查询到文件</td></tr>"
				}else{//id="+files[index].applyBatchNo+"
					for(index=0;index<files.length;index++){
						 content+="<tr onmouseover='moveoverMouse(this)' onmouseout='moveoutMouse(this)' align='center'><td width='2%'><input  name='ids' onclick='test(this)' type='checkbox' value="+files[index].applyBatchNo+" /></td><td width='78%' >"+files[index].applyBatchNo+"</td><td width='20%'><input id="+files[index].applyBatchNo+" type='hidden' /></td></tr>"; 
					 }
				}
				 $("#totalCount").text("条，共"+item.totalCount+"条");
				 $("select[name='numPerPage']").val(item.numPerPage); 
				 currentPage=item.currentPage;
				 numPerPage=item.numPerPage;
				 pageCount=item.pageCount;
				 totalCount=item.totalCount;
				 $("input[name='pageNum']").val(currentPage);
				 $("input[name='numPerPage']").val(numPerPage);
				 $("#tbodyByBatchApplication").html(content);
				 $("#paginationByBatchApplication").addClass("pagination").attr("targetType","navTab").attr("totalCount",totalCount).attr("numPerPage",numPerPage).attr("pageNumShown","10").attr("currentPage",currentPage).attr("rel","tbodyByBatchApplication").attr("callback","getApplicationBatchInfo");
				 $("div.pagination").each(function(){
					var $this = $(this);
					$this.pagination({
						targetType:"navTab",
						rel:"tbodyByBatchApplication",
						totalCount:totalCount,
						numPerPage:numPerPage,
						pageNumShown:10,
						currentPage:currentPage,
						callback:getApplicationBatchInfo
					});
				});
			 
			 var $p = $("#ByAppBatch");
			initUI($p);
				 for(var i=0;i<length;i++){
		    		$($("#"+errorFiles[i]).parent().parent().parent().children()[0]).children().children().attr("param","error");
					$($("#"+errorFiles[i]).parent().parent().parent().children()[0]).children().children().attr("checked","checked");
		    		$("#"+errorFiles[i]).parent().css("background-color", "red").text("导入的文件内容有错误");
				 }
			 });
		 },"json")	
	}
	 
	
 };
 function getUpdateApplicationSingle(json){
		$(json).each(function(n,item){
			if(!item.shgn){//修改是才执行回掉函数里面的内容
				$("input[name='customerName']").val(item.p.customerName);
				$("input[name='birth']").val(getDate(item.p.birthday));
				$("input[name='mobile']").val(item.p.mobile);
				$("input[name='curAddrDetailedInfo']").val(item.p.curAddrDetailedInfo);
				$("input[name='contactAddrDetailedInfo']").val(item.p.contactAddrDetailedInfo);
				$("input[name='homePhone']").val(item.p.homePhone);
				$("input[name='contactPostalcode']").val(item.p.contactPostalcode);
				$("input[name='email']").val(item.p.email);
				$("input[name='prAddrProvince']").val(item.p.prAddrProvince);
				$("input[name='prAddrCity']").val(item.p.prAddrCity);
				$("input[name='curAddrProvince']").val(item.p.curAddrProvince);
				$("input[name='curAddrCity']").val(item.p.curAddrCity);
				$("input[name='curAddrCounty']").val(item.p.curAddrCounty);
				$("input[name='curAddrStreet']").val(item.p.curAddrStreet);
				$("input[name='contactAddrProvince']").val(item.p.contactAddrProvince);
				$("input[name='contactAddrCity']").val(item.p.contactAddrCity);
				$("input[name='contactAddrCounty']").val(item.p.contactAddrCounty);
				$("input[name='contactAddrStreet']").val(item.p.contactAddrStreet);
				if(item.p.gender.indexOf("男")!=-1||item.p.gender=="01"){
				$("input[type='radio'][name='gender']").get(0).checked = true;//选中第一个
				}else{
					$("input[type='radio'][name='gender']").get(1).checked = true;
				}
				
				$.get("applicationSingle/nation",function(data){
					var contenta="<option value="+item.p.nationality+"> "
					+item.p.nationality+"</option>";
					var i;
					$(data).each(function(n,item){
			                for(i=0;i<item.Nation.length;i++){
							contenta+="<option value="+item.Nation[i].nationname+">"
							+item.Nation[i].nationname+"</option>"
						}
						$("#nationality").html(contenta);
				
						
					});
				},"json");
				$.get("applicationSingle/pro",function(data){
					var content="<option value="+item.p.prAddrProvince+"> "
					+item.p.prAddrProvince+"</option>";
					var contentb="<option value="+item.p.curAddrProvince+"> "
					+item.p.curAddrProvince+"</option>";
					var contentc="<option value="+item.p.contactAddrProvince+"> "
					+item.p.contactAddrProvince+"</option>";
					var i;
					$(data).each(function(n,item){
			                for(i=0;i<item.AddressProvince.length;i++){
							content+="<option value="+item.AddressProvince[i].provinceid+"> "
							+item.AddressProvince[i].province+"</option>"
						}
			                for(i=0;i<item.AddressProvince.length;i++){
								contentb+="<option value="+item.AddressProvince[i].provinceid+"> "
								+item.AddressProvince[i].province+"</option>"
							}
			                for(i=0;i<item.AddressProvince.length;i++){
								contentc+="<option value="+item.AddressProvince[i].provinceid+"> "
								+item.AddressProvince[i].province+"</option>"
							}
						$("#praddrProvince1").html(content);
						$("#curAddrProvince1").html(contentb);
						$("#contactAddrProvince1").html(contentc);
					
					});
				},"json");
				var content1="<option value="+item.p.prAddrCity+"> "
				+item.p.prAddrCity+"</option>";
				$("#prAddrCity1").html(content1);
				var content2="<option value="+item.p.curAddrCity+"> "
				+item.p.curAddrCity+"</option>";
				$("#curAddrCity1").html(content2);
				var content3="<option value="+item.p.curAddrCounty+"> "
				+item.p.curAddrCounty+"</option>";
				$("#curAddrCounty1").html(content3);
				var content4="<option value="+item.p.curAddrStreet+"> "
				+item.p.curAddrStreet+"</option>";
				$("#curAddrStreet1").html(content4);
				var content5="<option value="+item.p.contactAddrCity+"> "
				+item.p.contactAddrCity+"</option>";
				$("#contactAddrCity1").html(content5);
				var content6="<option value="+item.p.contactAddrCounty+"> "
				+item.p.contactAddrCounty+"</option>";
				$("#contactAddrCounty1").html(content6);
				var content7="<option value="+item.p.contactAddrStreet+"> "
				+item.p.contactAddrStreet+"</option>";
				$("#contactAddrStreet1").html(content7);
			}else{
				$.get("applicationSingle/nation",function(data){
					var contenta="<option value='' selected>请选择</option>";
					var i;
					$(data).each(function(n,item){
			                for(i=0;i<item.Nation.length;i++){
							contenta+="<option value="+item.Nation[i].nationname+">"
							+item.Nation[i].nationname+"</option>"
						}
						$("#nationality").html(contenta);
				
						
					});
				},"json");
			}
		})
	}
//获取时间
 function getBirthDate(str){    
	    var oDate = new Date(str).format('yyyy-MM-dd');
	     
	    return oDate;    
	};
Date.prototype.format = function(format) {
	       var date = {
	              "M+": this.getMonth() + 1,
	              "d+": this.getDate(),
	              "h+": this.getHours(),
	              "m+": this.getMinutes(),
	              "s+": this.getSeconds(),
	              "q+": Math.floor((this.getMonth() + 3) / 3),
	              "S+": this.getMilliseconds()
	       };
	       if (/(y+)/i.test(format)) {
	              format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
	       }
	       for (var k in date) {
	              if (new RegExp("(" + k + ")").test(format)) {
	                     format = format.replace(RegExp.$1, RegExp.$1.length == 1
	                            ? date[k] : ("00" + date[k]).substr(("" + date[k]).length));
	              }
	       }
	       return format;
	}